package com.hyperion.blog.controller;

import com.hyperion.blog.common.aop.LogAnnotation;
import com.hyperion.blog.service.SSOService;
import com.hyperion.blog.vo.ErrorCode;
import com.hyperion.blog.vo.params.LoginParam;
import com.hyperion.blog.vo.result.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Hyperion
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    private SSOService SSOService;

    @PostMapping
    @LogAnnotation(clazz = "LoginController", method = "login")
    public Result login(@RequestBody LoginParam loginParam) {
        String token = SSOService.login(loginParam);
        if (token == null) {
            return Result.fail(ErrorCode.PARAMS_ERROR);
        }
        return Result.success(token);
    }
}